package co.edu.unal.geditor.view.tools;

import java.awt.Point;
import java.awt.event.MouseEvent;

import javax.swing.SwingUtilities;

import co.edu.unal.geditor.controller.App;
import co.edu.unal.geditor.model.Drawing;
import co.edu.unal.geditor.model.GraphElement;

public abstract class CreationTool extends Tool {

	public abstract GraphElement createObject(Point ptPressed, Point ptReleased);

	// template method design pattern
	@Override
	public void processMouseReleased( MouseEvent me )
	{
		if (SwingUtilities.isLeftMouseButton(me)){
			Point ptReleased= me.getPoint();
			GraphElement ge = createObject( m_ptPressed, ptReleased );
			if(m_ptPressed.equals(ptReleased)==false && ge != null)
			{
				Drawing doc = App.getInstance().getDrawing();
				doc.addElement( ge );
			}
			else{
				App.getInstance().getCanvas().update();
			}
		}
	}
}
